// pages/volua/volua.js
const app = getApp();


Page({

  /**
   * 页面的初始数据
   */
  data: {

    VAILD: '', //判断是否领取
    USER_COUPON_PHONE: '', //领奖人电话
    COUPON_ID: '', //奖券ID
    jiangsj: '', //奖券参数
    wcwc: [],
    city: '',
    kajuan: '',
    dangx: '', //单个信息
    NEW_VAILD: '',
    flag: true, //设置节流
    // Getphone: false,





    slidingDistance: 0, //滑块滑动距离
    xDistance: 0, //滑块默认距离
    area_width: 60, //滑块容器总宽度 百分比
    box_width: 40, //滑块的宽px
    slidingWidth: 0, //滑动总宽度
    sliderValdationText: '拖动滑块验证',
    areaBgColor: '#fff',
    areaTextColor: '#666',

    huakuai: true


  },



  //点击拿数据
  xiang_q(e) {

    console.log(e);

   



    if (this.data.flag) {
      this.data.flag = false
      console.log(e.currentTarget);

      this.setData({
        dangx: e.currentTarget.dataset.item
      })

      this.receive_lin()

      // this.setData({
      //   huakuai: false
  
      // })

      setTimeout(() => {
        this.data.flag = true
      }, 5000)


    }
  },

  receive_lin() {

    wx.request({
      url: app.globalData.interface+'/shangluo/API2_1013_YueYueXiangCoupon',
      method: 'post',
      data: {
        COUPON_ID: this.data.dangx.COUPON_ID,
        // USER_COUPON_ID: this.data.dangx.USER_COUPON_ID,
        OPEN_ID: this.data.OPEN_ID, //用户OPEN_ID
        session_key: this.data.session_key,
        OPEN_UUID: this.data.jiami,
      },
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      },
      success: res => {
        console.log(res);
        wx.showModal({
          title: '温馨提示',
          content: res.data.data,
          success: function (res) {
            if (res.confirm) { //这里是点击了确定以后
              console.log('用户点击确定')
              wx.navigateBack({
                delta: 1,
              })
            } else { //这里是点击了取消以后
              console.log('用户点击取消')
              wx.navigateBack({
                delta: 1,
              })
            }
          }
        })
      }
    })
  },






  quanliebiao() {
    wx.request({
      url: app.globalData.interface+'/shangluo/API2_8311_ShangluoYueYueXiangSelect',
      method: 'post',
      data: {

        OPEN_ID: this.data.OPEN_ID, //用户OPEN_ID
        session_key: this.data.session_key,
        OPEN_UUID: this.data.jiami,
      },
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      },
      success: res => {
        console.log(res.data);

        if (res.data.result != 'success') {
          if (res.data.code == 0) {
            wx.navigateTo({
              url: '../../pages/newquanyizhuce/newquanyizhuce',
            })
          } else {
            wx.showModal({
              title: '温馨提示',
              content: '内部错误！请稍后再试！',
              success: function (res) {
                if (res.confirm) { //这里是点击了确定以后
                  console.log('用户点击确定')
                  wx.navigateBack({
                    delta: 1,
                  })
                } else { //这里是点击了取消以后
                  console.log('用户点击取消')
                  wx.navigateBack({
                    delta: 1,
                  })
                }
              }
            })
          }
        } else {
          this.setData({
            jiangsj: res.data.data.prize
          })
        }
      }
    })
  },




  //拖动滑块触发
  sliderDrag: function (e) {
    let that = this;
    that.setData({
      slidingDistance: e.detail.x
    });
  },

  //触摸结束
  sliderDragOver: function (e) {
    var that = this;
    if (that.data.slidingDistance >= that.data.slidingWidth) {
      console.log(that.data.slidingDistance, that.data.slidingWidth);
      that.setData({
        sliderValdationText: '验证成功',
        areaBgColor: '#fd8649',
        areaTextColor: '#fff'
      });

      wx.showToast({
        title: '验证成功',
        duration: 2000
      })



      setTimeout(() => {
        this.setData({
          huakuai: true,
          slidingDistance: 0, //滑块滑动距离
          xDistance: 0, //滑块默认距离
          area_width: 85, //滑块容器总宽度 百分比
          box_width: 40, //滑块的宽px
          slidingWidth: 0, //滑动总宽度
          sliderValdationText: '拖动滑块验证',
          areaBgColor: '#fff',
          areaTextColor: '#666',
        })

      }, 1000)



    } else {
      that.setData({
        xDistance: 0
      })
    }
  },
















  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (e) {

    setTimeout(() => {
      this.setData({
        jiami: app.globalData.jiami,
        OPEN_ID: app.globalData.openid,
        openid: app.globalData.openid,
        session_key: app.globalData.session_key,
      })

      this.quanliebiao()

    }, 800)

    let that = this;
    wx.getSystemInfo({
      success: function (res) {
        var sWidth = Math.floor(res.windowWidth * that.data.area_width / 100 - that.data.box_width)
        that.setData({
          slidingWidth: sWidth
        });
      }
    })

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {




  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})